package cn.edu.zut.dao;

import cn.edu.zut.domain.AwardsInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AwardsDao {
    //添加一条获奖信息
    @Insert("insert into awards(_id, STNumber, relName, className, contestName, awardLevel, depName) values(#{_id}, #{STNumber}, #{relName}, #{className}, #{contestName}, #{awardLevel}, #{depName})")
    public void add(AwardsInfo awardsInfo);
    //修改获奖信息
    @Update("update awards set STNumber = #{STNumber}, relName = #{relName}, className = #{className}, contestName = #{contestName}, awardLevel = #{awardLevel}, depName = #{depName} where _id = #{_id}")
    public void update(AwardsInfo awardsInfo);
    //根据_id删除获奖信息
    @Delete("delete from awards where _id = #{id}")
    public void deleteByUserId(int id);
    //查询所有获奖信息
    @Select("select * from awards")
    public List<AwardsInfo> findAll();
    //根据_id查询获奖信息
    @Select("select * from awards where _id = #{id}")
    public AwardsInfo findByUserId(int id);
    //根据学号、竞赛名称、获奖等级查询获奖信息
    @Select("select * from awards where STNumber = #{arg0} and contestName = #{arg1} and awardLevel = #{arg2}")
    public AwardsInfo findBySTNumberAndContestAndAward(String STNumber, String contestName, String awardLevel);
    //根据学号、竞赛名称、获奖等级迷糊查询获奖信息
    @Select("select * from awards where STNumber like CONCAT('%',#{arg0},'%') and contestName like CONCAT('%',#{arg1},'%') and awardLevel like CONCAT('%',#{arg2},'%')")
    public List<AwardsInfo> findLikeByPrint(String STNumber, String contestName, String awardLevel);
    //根据学号查询获奖信息
    @Select("select * from awards where STNumber = #{STNumber}")
    public List<AwardsInfo> findBySTNumber(String STNumber);
    //根据竞赛名称查询获奖信息
    @Select("select * from awards where contestName = #{contestName}")
    public List<AwardsInfo> findByContestName(String contestName);
    //根据获奖等级和竞赛名称查询获奖信息
    @Select("<script>" +
            "SELECT * FROM awards where 1 = 1" +
            "<if test=\"awardLevel != null and awardLevel != ''\">" +
            " and awardLevel = #{awardLevel}" +
            "</if>" +
            "<if test=\"contestName != null and contestName != ''\">" +
            " and contestName = #{contestName}" +
            "</if>"
            + "</script>"
    )
    public List<AwardsInfo> findAllByPrint(AwardsInfo awardsInfo);
}
